﻿Imports System.Data.OleDb
Imports System.Data

Public Class details
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim quizGUID As String = Request.Params("GUID")
        If quizGUID Is Nothing Then
            Response.Redirect("~/list.aspx")
        Else
            Dim quiz As QuizModel = New QuizModel(quizGUID)

            If Not quiz.IsSaved Then
                placeholder_cantFind.Visible = True
            Else
                lbl_questionCount.Text = quiz.QuestionCount
                lbl_title.Text = quiz.Title
                If Not IsDBNull(quiz.Description) Then
                    placeholder_description.Visible = True
                    lbl_description.Text = quiz.Description
                End If

                UserFlash.UserName = quiz.CreatorID

                If IsPostBack Then
                    placeholder_submitted.Visible = True
                    placeholder_questions.Visible = False

                    rptr_submitted.DataSource = quiz.DataSet
                    rptr_submitted.DataBind()
                Else
                    placeholder_questions.Visible = True

                    rptr_questions.DataSource = quiz.DataSet
                    rptr_questions.DataBind()

                End If
            End If

        End If
    End Sub

    Public Sub callback_submitted_onItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
        Dim item As RepeaterItem
        Dim type As ListItemType
        Dim rptr As Repeater
        Dim drv As DataRowView

        item = e.Item
        type = item.ItemType
        If type = ListItemType.Item OrElse type = ListItemType.AlternatingItem Then
            rptr = DirectCast(item.FindControl("rptr_submitted_answers"), Repeater)
            drv = DirectCast(item.DataItem, DataRowView)
            rptr.DataSource = drv.CreateChildView("QuestionMultipleChoiceAnswerRelation")
            rptr.DataBind()
        End If
    End Sub


End Class